﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace CustomNetworking
{
    class SimpleClient
    {
        private static System.Text.Encoding encoding = new UTF8Encoding();
        
        static void Main(string[] args)
        {
            new SimpleClient();
            Console.ReadLine();
        }

        public SimpleClient()
        {
            TcpClient client = new TcpClient("localhost", 4000);
            Socket s = client.Client;

            StringSocket socket = new StringSocket(s, new UTF8Encoding());

            socket.BeginSend(GenerateString(5000, 'a'), MessageSent, 1);

            //Thread.Sleep(500);

            socket.BeginSend(GenerateString(5000, 'b'), MessageSent, 2);

            //Thread.Sleep(500);

            socket.BeginSend(GenerateString(5000, 'c'), MessageSent, 3);
        }

        private void MessageSent(Exception o, object payload)
        {
            Console.WriteLine("Sent message: " + payload.ToString());
        }

        private static string GenerateString(int count, char c)
        {
            string s = "start ";
            Random rand = new Random();

            for (int i = 0; i < count; i++)
            {
                s += c;
            }

            return s + " end\n";
        }
    }
}
